package com.tedu.checkIn.service.impl;

import com.tedu.checkIn.mapper.BedMapper;
import com.tedu.checkIn.pojo.dto.BedParam;
import com.tedu.checkIn.pojo.dto.BedQuery;
import com.tedu.checkIn.pojo.entity.Bed;
import com.tedu.checkIn.pojo.vo.BedVO;
import com.tedu.checkIn.service.BedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class BedServiceImpl implements BedService {
    @Autowired
    BedMapper bedMapper;

    @Override
    public List<BedVO> selectBed(BedQuery bedQuery) {
        log.debug("查询床位业务，参数={}",bedQuery);
        List<BedVO> list=bedMapper.selectBed(bedQuery);
        log.debug("查询床位业务，入数={},出参{}",bedQuery,list);
        return list;
    }

    @Override
    public void saveBed(BedParam bedParam) {
        log.debug("保存床位业务，参数={}",bedParam);
        Bed bed=new Bed();
        BeanUtils.copyProperties(bedParam,bed);
        if (bed.getId() == null){//新增
            bed.setCreateTime(new Date());
            bed.setStatus("1");
            bedMapper.insertBed(bed);
        }else {//修改
            bed.setUpdateTime(new Date());
            bedMapper.updateBed(bed);
        }
    }

    @Override
    public void updateStatus(Integer id, String status) {
        log.debug("修改床位状态业务，参数={},参数={}",id,status);
        Bed bed=new Bed();
        bed.setId(id);
        bed.setStatus(status);
        bed.setUpdateTime(new Date());
        bedMapper.updateBed(bed);
    }

    @Override
    public void deleteBed(Integer id) {
        log.debug("删除床位业务，参数={}",id);
        bedMapper.deleteById(id);
    }


}
